//Turn leadway is in deciseconds, like sleep()
//Turn leadway moved to master config file


TurnController
	var
		list
			pcList
			pcWithMove
			npcList = list()
		leadway = TURN_LEADWAY as num //The number of ticks before a move is forced
		Timer/Timer
	New()
		pcList = list()
		pcWithMove = list()
	proc
		AddMob(mob/M as mob)
			if(istype(M,/mob/pc))
				pcList.Add(M)
				pcWithMove.Add(M)
			else
				npcList.Add(M)
			if(M.TurnController) M.TurnController.RemoveMob(M)
			M.TurnController = src
		RemoveMob(mob/M as mob)
			if(istype(M,/mob/pc))
				pcList.Remove(M)
				if(M in pcWithMove) pcWithMove.Remove(M)
			else
				if(M in npcList) npcList.Remove(M)
			if(!pcList.len)
				for(var/mob/monster/mon in npcList)
					mon.NewTurnController()
				del(src)
		Action(mob/pc/M as mob)
			if(!M.combat)
				for(var/mob/monster/mon in npcList)
					spawn()
						if(mon) mon.AIMove()
				return 1
			if(!pcWithMove.Find(M)) return 0
			pcWithMove.Remove(M)
			if(!pcWithMove.len)
				if(src.Timer) src.StopTimer()
				for(var/mob/monster/mon in npcList)
					spawn()
						if(mon) mon.AIMove()
				pcWithMove.Add(pcList)
				return 1
			if(pcList.len > 1) src.StartTimer()
			return 1
		CheckAction(mob/pc/M as mob)
			if(!M.combat) return 1
			if(!pcWithMove.Find(M)) return 0
			return 1
		StartTimer()
			if(src)
				var/Timer/T = new(leadway,"ForceMoves", src)
				Timer = T
				return 1
		StopTimer()
			if(Timer) del Timer
			return 1
		ResetTimer()
			StopTimer()
			StartTimer()
			return 1
		ForceMoves()
			for(var/mob/pc/P in pcWithMove)
				P.ForceMove()
			pcWithMove = new()
			src.StopTimer()
			pcWithMove.Add(pcList)
			return 1

	Dummy
		Action()
			return 1
		CheckAction()
			return 1
		New()
			pcList = list()
		RemoveMob(mob/M as mob)
			return 1
		AddMob(mob/M as mob)
			if(istype(M,/mob/pc))
				pcList.Add(M)
			else
				npcList.Add(M)
			if(M.TurnController) M.TurnController.RemoveMob(M)
			M.TurnController = src
